//
//  MayLikeView.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/11.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "MayLikeView.h"
#import "MayLikeModel.h"

@interface MayLikeView()

@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *moneyLabel;

@end

@implementation MayLikeView

-(void)mayNeedClicked:(id)tap
{
    if (_mayNeedClick) {
        _mayNeedClick();
    }
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        UIView *headBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        headBg.layer.borderColor = REXADECIMALCOLOR(@"#dcdcdc").CGColor;
        headBg.layer.borderWidth = 1;
        headBg.layer.cornerRadius = ScreenX375(2);
        headBg.clipsToBounds = YES;
        headBg.userInteractionEnabled = true;
        [self addSubview:headBg];
        
        self.headImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, ScreenX375(113))];
        UIGestureRecognizer *tap = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(mayNeedClicked:)];
        self.headImage.userInteractionEnabled = YES;
        [self.headImage addGestureRecognizer:tap];
        [headBg addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(6), ScreenX375(121), frame.size.width - ScreenX375(12), ScreenX375(16))];
        self.nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
        self.nameLabel.font = Kfont(14);
        [headBg addSubview:self.nameLabel];
        
        self.moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(6), ScreenX375(140), ScreenX375(100), ScreenX375(18))];
        self.moneyLabel.textColor = ThemeColor;
        self.moneyLabel.font = Kfont(14);
        [headBg addSubview:self.moneyLabel];
    }
    return self;
}

-(void)initWithModel:(MayLikeModel *)model{
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:model.index_pic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.nameLabel.text = model.card_name;
    NSString *price = [NSString stringWithFormat:@"¥%@",model.price];
    self.moneyLabel.text = price;
}

@end
